<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>新增商品类别</title>
		<link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/default/easyui.css" />" rel="stylesheet" type="text/css">
		<link href="<c:url value="/resources/css/icon.css" />" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="<c:url value="/resources/js/jquery-1.7.2.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/jquery.easyui.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="/resources/js/easyui-lang-zh_CN.js" />"></script>
		<script type="text/javascript">
			function onAddCategory(){
				$.ajax({
					type:"post",
					url:"addCategory.do",
					data:{product_category_name:$.trim($("#product_category_name").val()), 
						  description:$("#description").val()},
					success:function(data){						
						if(data == "success"){
							data = "新增商品类别成功";
							onResetCategory();
						}
						$.messager.alert('操作结果', data);
					}
				});
			}
			
			function onResetCategory(){
				$("#product_category_name").val('');
				$("#description").val('');
			}
			
			function onResetSubCategory(){
				$("#product_category_id").combobox("select", "1");
				$("#product_sub_category_name").val('');
				$("#subDescription").val('');
			}
			
			function onAddSubCategory(){
				$.ajax({
					type:"post",
					url:"addSubCategory.do",
					data:{product_sub_category_name:$.trim($("#product_sub_category_name").val()), 
						  description:$("#subDescription").val(),
						  product_category_id:$("#product_category_id").combobox('getValue')},
					success:function(data){
						if(data == "success"){
							data = "新增商品子类成功";
							onResetSubCategory();
						}
						$.messager.alert('操作结果', data);
					}
				});
			}
		</script>
	</head>
	<body>
		<div id="sss" class="easyui-tabs" style="width:700px;height:250px" data-options="fit:true,onSelect:function(title){
			if(title == '新增商品子类'){
				$('#product_category_id').combobox('reload','getCategorySel.do'); 
			}
		}">
			<div title="新增商品类别" style="padding:10px">
				<form name="addCategoryForm" id="addCategoryForm" method="post" action="addCategory">
					<table  style="text-align: center; border:1px;width:400px;">						
						<tr>
							<td align="right" style="height:28px;">商品类别名称：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" 
	    							name="product_category_name" id="product_category_name" required="true" />
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">商品类别描述：</td>
	    					<td align="left">
	    						<textarea class="easyui-validatebox" style="width:250px;height: 100px;" name="description" id="description" ></textarea>
	    					</td>
						</tr>
						
						
						<tr>
							<td colspan="2">
								<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onAddCategory()">保存</a>
	    						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onResetCategory()">重置</a>
							</td>
						</tr>
					</table>
				</form>
			</div>
			
			<div title="新增商品子类" style="padding:10px" >
				<form name="addSubCategoryForm" id="addSubCategoryForm" method="post" action="addSubCategory">
					<table  style="text-align: center; border:1px;width:400px;">
						<tr>
							<td align="right" style="height:28px;">商品类别：</td>
	    					<td align="left">
	    						<select  class="easyui-combobox" style="width:155px;"  name="product_category_id" id="product_category_id" 
	    							data-options="required:true, panelHeight:'auto', valueField:'id', textField:'product_category_name'">	    							
	    							<c:forEach var="code" items="${categoryList}">
	    								<option value="${code.id}">${code.product_category_name}</option>	
	    							</c:forEach>
	    						</select>
	    					</td>
						</tr>
										
						<tr>
							<td align="right" style="height:28px;">商品子类名称：</td>
	    					<td align="left">
	    						<input class="easyui-validatebox" style="width:150px;" type="text" 
	    							name="product_sub_category_name" id="product_sub_category_name" required="true"/>
	    					</td>
						</tr>
						
						<tr>
							<td align="right" style="height:28px;">商品子类描述：</td>
	    					<td align="left">
	    						<textarea class="easyui-validatebox" style="width:250px;height: 100px;"  name="subDescription" id="subDescription" ></textarea>
	    					</td>
						</tr>
						
						<tr>
							<td colspan="2">
								<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onAddSubCategory()">保存</a>
	    						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="onResetSubCategory()">重置</a>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>
</html>